$(function() {
	$(".scanPwd").click(function() {

		//隐藏 、 查看密码
		if (!$(this).hasClass("scan")) {

			$(this).addClass("scan")
				.attr("src", "img/login/icon-show@2x.png")
				.prev("input")
				.attr("type", "text");

		} else {

			$(this).removeClass("scan")
				.attr("src", "img/login/icon-hide@2x.png")
				.prev("input")
				.attr("type", "password");

		}

	});

	$('.btn').click(function() {
		let name = $('#username').val();
		let password = $('#password').val();
		$.ajax({
			type: 'get',
			url: http + 'login',
			data: {
				username: name,
				password: password
			},
			dataType: "json",
			async: true,
			success: function(res) {
				if(res.code == 200){
					let data = eval('(' + res.data + ')');
					console.log(data)
					localStorage.setItem('user_id', data.user_id);
					localStorage.setItem('auth_str', data.auth_str);
					window.location.href = 'navigation.html'
				}else{
					alert(res.msg)
				}
			},
			error: function() {
				console.log('访问失败');
			}
		});
	})
})
